package com.googlecode.gwtbb.client.only.widget.basic;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public class AsyncFileUpload extends AsyncFileUploadBase {
	// the widget that displays the upload prompt
	private Panel uploadPanel;
	// the widget that displays something after the file has been uploaded
	private FlowPanel uploadedPanel;
	// parts of the uploadedPanel
	private Label uploadedLabel;

	// the widget that displays some intermediate message while uploading
	private FlowPanel uploadingPanel;
	// parts of the uploadingPanel
	private Label uploadingLabel;

	public AsyncFileUpload(String formAction) {
		super(formAction);
	}

	public Widget getStatusDeletedWidget() {
		// todo implement
		return getStatusUploadedWidget();
	}

	public Widget getStatusEmptyWidget() {
		if (uploadPanel == null) {
			uploadPanel = new FlowPanel();
			Hypolink hypolink = new Hypolink("Click to upload file");
			uploadPanel.add(hypolink);
			hypolink.addClickListener(promptFileUploadClickListener);
		}
		return uploadPanel;
	}

	public Widget getStatusUploadedWidget() {
		if (uploadedPanel == null) {
			uploadedPanel = new FlowPanel();
			uploadedLabel = new Label();
			uploadedPanel.add(uploadedLabel);
		}
		return uploadedPanel;
	}

	public Widget getStatusUploadingWidget() {
		if (uploadingPanel == null) {
			uploadingPanel = new FlowPanel();
			uploadingLabel = new Label();
			uploadingPanel.add(uploadingLabel);
		}
		return uploadingPanel;
	}

	public void onDeleted() {
	}

	public void onUploaded() {
		uploadedLabel.setText(getClientFileName() + " ready");
	}

	public void onUploading(String fileName) {
		uploadingLabel.setText("Uploading " + fileName);
	}
}
